import request from "@/utils/request";
import type {
  DataSource,
  DataSourceQuery,
  DataSourceResponse,
} from "@/types/dataSource";

export const getDataSourceList = (params: DataSourceQuery) => {
  return request.get<DataSourceResponse>("/api/data-sources", { params });
};

export const createDataSource = (data: Omit<DataSource, "id">) => {
  return request.post<DataSource>("/api/data-sources", data);
};

export const updateDataSource = (id: number, data: Partial<DataSource>) => {
  return request.put<DataSource>(`/api/data-sources/${id}`, data);
};

export const deleteDataSource = (id: number) => {
  return request.delete(`/api/data-sources/${id}`);
};

export const testDataSourceConnection = (id: number) => {
  return request.post<{ success: boolean; message: string }>(
    `/api/data-sources/${id}/test`
  );
};
